home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / iso9660 / ip / manage / snmp / patches.shr / parse.c.diff < prev    next >
Encoding:
Text File  |  1992-01-15  |  7.9 KB  |  359 lines

  1. ===================================================================
  2. RCS file: /s/usr2/K/repo/tools/cmu-snmp/snmplib/parse.c,v
  3. retrieving revision 1.1
  4. diff -c -r1.1 parse.c
  5. *** /tmp/,RCSt1a22340    Tue Sep 24 20:22:59 1991
  6. --- parse.c    Thu Sep 19 06:18:15 1991
  7. ***************
  8. *** 1,3 ****
  9. --- 1,4 ----
  10. + /* $Id: parse.c,v 1.3 91/09/19 06:18:33 phil Exp $    */
  11.   /***********************************************************
  12.       Copyright 1989 by Carnegie Mellon University
  13.   
  14. ***************
  15. *** 69,74 ****
  16. --- 70,80 ----
  17.   #define RECOMMENDED 26
  18.   #define PUNCT        27
  19.   #define EQUALS        28
  20. + #define DESCRIPTION 29
  21. + #define QUOTESTRING 30
  22. + #define INDEX        31
  23. + #define DEFVAL        32
  24. + #define DEPRECATED  33
  25.   
  26.   struct tok {
  27.       char *name;            /* token name */
  28. ***************
  29. *** 113,121 ****
  30. --- 119,132 ----
  31.       { "{", sizeof ("{")-1, PUNCT },
  32.       { "}", sizeof ("}")-1, PUNCT },
  33.       { "::=", sizeof ("::=")-1, EQUALS },
  34. +         { "DESCRIPTION", sizeof ("DESCRIPTION")-1, DESCRIPTION },
  35. +         { "INDEX", sizeof ("INDEX")-1, INDEX },
  36. +         { "DEFVAL", sizeof ("DEFVAL")-1, DEFVAL },
  37. +     { "deprecated", sizeof ("deprecated")-1, DEPRECATED },
  38.       { NULL }
  39.   };
  40.   
  41.   #define    HASHSIZE    32
  42.   #define    BUCKET(x)    (x & 0x01F)
  43.   
  44. ***************
  45. *** 341,347 ****
  46.   {
  47.       register int count;
  48.       int type;
  49. !     char token[64], label[32];
  50.       register char *cp, *tp;
  51.   
  52.       if ((type = get_token(fp, token)) != PUNCT){
  53. --- 352,358 ----
  54.   {
  55.       register int count;
  56.       int type;
  57. !     char token[MAXTOKEN], label[MAXLABEL];
  58.       register char *cp, *tp;
  59.   
  60.       if ((type = get_token(fp, token)) != PUNCT){
  61. ***************
  62. *** 430,436 ****
  63.       char *name;
  64.   {
  65.       int type;
  66. !     char token[64];
  67.       register int count;
  68.       register struct subid *op, *nop;
  69.       int length;
  70. --- 441,447 ----
  71.       char *name;
  72.   {
  73.       int type;
  74. !     char token[MAXTOKEN];
  75.       register int count;
  76.       register struct subid *op, *nop;
  77.       int length;
  78. ***************
  79. *** 516,526 ****
  80.       FILE *fp;
  81.   {
  82.       int type;
  83. !     char token[64];
  84.   
  85.       type = get_token(fp, token);
  86.       if (type != SEQUENCE){
  87. !     print_error("Not a sequence", (char *)NULL); /* should we handle this */
  88.       return NULL;
  89.       }
  90.       while((type = get_token(fp, token)) != NULL){
  91. --- 527,537 ----
  92.       FILE *fp;
  93.   {
  94.       int type;
  95. !     char token[MAXTOKEN];
  96.   
  97.       type = get_token(fp, token);
  98.       if (type != SEQUENCE){
  99. !     type = get_token(fp, token);
  100.       return NULL;
  101.       }
  102.       while((type = get_token(fp, token)) != NULL){
  103. ***************
  104. *** 543,554 ****
  105.       char *name;
  106.   {
  107.       register int type;
  108. !     char token[64];
  109.       int count, length;
  110.       struct subid oid[16];
  111. !     char syntax[32];
  112.       int nexttype;
  113. !     char nexttoken[64];
  114.       register struct node *np;
  115.       register struct enum_list *ep;
  116.       register char *cp;
  117. --- 554,565 ----
  118.       char *name;
  119.   {
  120.       register int type;
  121. !     char token[MAXTOKEN];
  122.       int count, length;
  123.       struct subid oid[16];
  124. !     char syntax[MAXTOKEN];
  125.       int nexttype;
  126. !     char nexttoken[MAXTOKEN];
  127.       register struct node *np;
  128.       register struct enum_list *ep;
  129.       register char *cp;
  130. ***************
  131. *** 706,717 ****
  132.       return 0;
  133.       }
  134.       type = get_token(fp, token);
  135. !     if (type != MANDATORY && type != OPTIONAL && type != OBSOLETE && type != RECOMMENDED){
  136.       print_error("Bad status", token);
  137.       free_node(np);
  138.       return 0;
  139.       }
  140.       type = get_token(fp, token);
  141.       if (type != EQUALS){
  142.       print_error("Bad format", token);
  143.       free_node(np);
  144. --- 717,760 ----
  145.       return 0;
  146.       }
  147.       type = get_token(fp, token);
  148. !     if (type != MANDATORY && type != OPTIONAL && type != OBSOLETE && type != RECOMMENDED && type != DEPRECATED){
  149.       print_error("Bad status", token);
  150.       free_node(np);
  151.       return 0;
  152.       }
  153.       type = get_token(fp, token);
  154. +     /*
  155. +      * Optional parts of the OBJECT-TYPE macro
  156. +      */
  157. +     while (type != EQUALS) {
  158. +     int breakFlag = 0;
  159. +     switch (type) {
  160. +       case DESCRIPTION:
  161. +         type = get_token(fp, token);
  162. +         if (type != QUOTESTRING) {
  163. +         print_error("Bad DESCRIPTION", token);
  164. +         free_node(np);
  165. +         return 0;
  166. +         }
  167. +         break;
  168. +       case INDEX:
  169. +       case DEFVAL:
  170. +         if (tossObjectIdentifier(fp, token) != OBJID) {
  171. +         print_error("Bad Object Identifier", token);
  172. +         free_node(np);
  173. +         return 0;
  174. +         }
  175. +         break;
  176. +       default:
  177. +         print_error("Bad format of optional clauses", token);
  178. +         free_node(np);
  179. +         return 0;
  180. +         break;
  181. +     }
  182. +     type = get_token(fp, token);
  183. +     }
  184.       if (type != EQUALS){
  185.       print_error("Bad format", token);
  186.       free_node(np);
  187. ***************
  188. *** 721,727 ****
  189.       if (length > 1 && length <= 16){
  190.       /* just take the last pair in the oid list */
  191.       if (oid[length - 2].label)
  192. !         strncpy(np->parent, oid[length - 2].label, 32);
  193.       strcpy(np->label, name);
  194.       if (oid[length - 1].subid != -1)
  195.           np->subid = oid[length - 1].subid;
  196. --- 764,770 ----
  197.       if (length > 1 && length <= 16){
  198.       /* just take the last pair in the oid list */
  199.       if (oid[length - 2].label)
  200. !         strncpy(np->parent, oid[length - 2].label, MAXLABEL);
  201.       strcpy(np->label, name);
  202.       if (oid[length - 1].subid != -1)
  203.           np->subid = oid[length - 1].subid;
  204. ***************
  205. *** 750,757 ****
  206.   parse(fp)
  207.       FILE *fp;
  208.   {
  209. !     char token[64];
  210. !     char name[32];
  211.       int    type = 1;
  212.       struct node *np, *root = NULL;
  213.   
  214. --- 793,800 ----
  215.   parse(fp)
  216.       FILE *fp;
  217.   {
  218. !     char token[MAXTOKEN];
  219. !     char name[MAXLABEL];
  220.       int    type = 1;
  221.       struct node *np, *root = NULL;
  222.   
  223. ***************
  224. *** 766,772 ****
  225.           print_error(token, "is a reserved word");
  226.           return NULL;
  227.       }
  228. !     strncpy(name, token, 32);
  229.       type = get_token(fp, token);
  230.       if (type == OBJTYPE){
  231.           if (root == NULL){
  232. --- 809,815 ----
  233.           print_error(token, "is a reserved word");
  234.           return NULL;
  235.       }
  236. !     strncpy(name, token, MAXTOKEN);
  237.       type = get_token(fp, token);
  238.       if (type == OBJTYPE){
  239.           if (root == NULL){
  240. ***************
  241. *** 806,811 ****
  242. --- 849,859 ----
  243.           np = np->next;
  244.       } else if (type == EQUALS){
  245.           type = parse_asntype(fp);
  246. +         if (type != NULL) {
  247. +         /* equivalenced type: DdpAddress :== OCTET STRING */
  248. +         /* What to do?  */
  249. +         }
  250. +         
  251.       } else if (type == NULL){
  252.           break;
  253.       } else {
  254. ***************
  255. *** 813,818 ****
  256. --- 861,867 ----
  257.           return NULL;
  258.       }
  259.       }
  260. +     
  261.   #ifdef TEST
  262.   {
  263.       struct enum_list *ep;
  264. ***************
  265. *** 854,859 ****
  266. --- 903,910 ----
  267.       ch = getc(fp);
  268.       if (ch == '\n')
  269.           Line++;
  270. +     else if (ch == '"')
  271. +         return parseQuoteString(fp, token);
  272.       }
  273.       if (ch == -1)
  274.       return NULL;
  275. ***************
  276. *** 900,905 ****
  277. --- 951,1028 ----
  278.       
  279.       } while ((ch = getc(fp)) != -1);
  280.       return NULL;
  281. + }
  282. + static int
  283. + parseQuoteString(fp, token)
  284. +     register FILE *fp;
  285. +     register char *token;
  286. + {
  287. +     static char last = ' ';
  288. +     register int ch;
  289. +     register char *cp = token;
  290. +     register int hash = 0;
  291. +     register struct tok *tp;
  292. +     ch = ' ';
  293. +     
  294. +     while(ch != -1) {
  295. +     ch = getc(fp);
  296. +     cp++;
  297. +     
  298. +     if (ch == '\n')
  299. +         Line++;
  300. +     else if (ch == '"') {
  301. +         return QUOTESTRING;
  302. +     }
  303. +     }
  304. +     if (ch == -1) {
  305. +     last = ch;
  306. +     *cp = '\0';
  307. +     return NULL;
  308. +     }
  309. + }
  310. + /*
  311. +  * This routine parses a string like  { blah blah blah } and returns OBJID if
  312. +  * it is well formed, and NULL if not.
  313. +  */ 
  314. + static int
  315. + tossObjectIdentifier(fp, token)
  316. +     register FILE *fp;
  317. +     register char *token;
  318. + {
  319. +     static char last = ' ';
  320. +     register int ch;
  321. +     register char *cp = token;
  322. +     register int hash = 0;
  323. +     register struct tok *tp;
  324. +     ch = last;
  325. +     /* skip all white space */
  326. +     while(isspace(ch) && ch != -1){
  327. +     ch = getc(fp);
  328. +     if (ch == '\n')
  329. +         Line++;
  330. +     }
  331. +     if (ch != '{')
  332. +     return NULL;
  333. +     
  334. +     while(ch != -1) {
  335. +     ch = getc(fp);
  336. +     cp++;
  337. +     
  338. +     if (ch == '\n')
  339. +         Line++;
  340. +     else if (ch == '}')
  341. +         return OBJID;
  342. +     }
  343. +     if (ch == -1){
  344. +     last = ch;
  345. +     *cp = '\0';
  346. +     return NULL;
  347. +     }
  348.   }
  349.   
  350.   struct tree *
  351.